package com.whp.yky.yky.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.whp.yky.yky.entity.Notice;
import com.whp.yky.yky.mapper.NoticeMapper;
import com.whp.yky.yky.service.NoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zwq
 * @since 2021-03-02
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public IPage<Notice> getNoticeInfo(IPage<Notice> page) {
        return page.setRecords(noticeMapper.getNoticeInfo(page));
    }

    @Override
    public Notice getNoticeDetailInfo(Integer id) {
        return noticeMapper.getNoticeDetailInfo(id);
    }

    @Override
    public boolean insertNoticeDetailInfo(Notice notice) {
        try {
            int effecteNum= noticeMapper.insertNoticeDetailInfo(notice);
            if(effecteNum>0){
                return true;
            }else {
                throw  new RuntimeException("插入信息失败,插入行数有误");
            }
        }catch (Exception e){
            throw  new RuntimeException("插入信息失败了:"+e.getMessage());
        }
    }

    @Override
    public boolean saveNoticeDetailInfo(Notice notice) {
        try {
            int effecteNum= noticeMapper.saveNoticeDetailInfo(notice);
            if(effecteNum>0){
                return true;
            }else {
                throw  new RuntimeException("插入信息失败,插入行数有误");
            }
        }catch (Exception e){
            throw  new RuntimeException("插入信息失败了:"+e.getMessage());
        }
    }

    @Override
    public List<Notice> getNoticeList() {
        return noticeMapper.getNoticeList();
    }

}
